/*
 * Created on May 24, 2004
 * by Mihai Postelnicu
 * email mihai@code.ro
 *
 *
 */
package ro.gateway.aida.search;

import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
import ro.gateway.aida.obj.LocalizedItem;
import ro.gateway.aida.servlet.Constants;

/**
 * @author Mihai Postelnicu email mihai@code.ro
 */
public abstract class ResultCell extends LocalizedItem implements Comparable {
	protected String type;

	protected long projectId;

	protected boolean list;

	public String getUniqueId() {
		return type + projectId;
	}

	public abstract int compareTo(Object o);

	public String toString() {
		return "--";
	}

	public String getType() {
		return type;
	}

	public ResultCell(String type) {
		this.type = type;
		list = false;
	}

	/**
	 * @return Returns the projectId.
	 */
	public long getProjectId() {
		return projectId;
	}

	/**
	 * @param projectId
	 *            The projectId to set.
	 */
	public void setProjectId(long projectId) {
		this.projectId = projectId;
	}

	/**
	 * @return Returns the list.
	 */
	public boolean isList() {
		return list;
	}

	/**
	 * Appends the cells to the outer Excel sheet. By default a String
	 * representation of the current cell is appended. Override in descendants!
	 * 
	 * @param sheet
	 *            the writeable excel sheet
	 * @param x
	 *            the x cell position
	 * @param y
	 *            the y cell position
	 * @return the number of appended cells (1 by default)
	 * @throws RowsExceededException
	 * @throws WriteException
	 */
	public int appendXlsCells(WritableSheet sheet, int x, int y, boolean header)
			throws RowsExceededException, WriteException {
		if (header)
			sheet.addCell(new Label(x, y, type.toUpperCase(),Constants.times12format));
		else
			sheet.addCell(new Label(x, y, toString()));
		return 1;
	}

}